#include "LinkedList.h"

#ifdef __cplusplus
extern "C"
{
#endif

LL_Element *LL_AppendElement(LL_Element *First, LL_Element *Second)
{
	First->Next = Second;
	Second->Next = (LL_Element *)NULL;
	return First;
}

LL_Element *LL_InsertElement(LL_Element *First, LL_Element *Second)
{
	LL_Element *TempPointer = First->Next;
	First->Next = Second;
	Second->Next = TempPointer;
	return First;	
}

LL_Element *LL_GetNthElementFrom(LL_Element *From, int N)
{
	int X;
	LL_Element *CurrentPointer = From;
	for(X = 0; X < N; ++X)
	{
		CurrentPointer = CurrentPointer->Next;
		if(CurrentPointer == NULL)
			return NULL;
	}
	return CurrentPointer;
}

int LL_GetSizeFrom(LL_Element *From)
{
	int Size = 0;
	LL_Element *Current = From;
	while(Current->Next != NULL)
	{
		++Size;
		Current = Current->Next;
	}
	return Size + 1;
}

LL_Element *LL_RemoveElementsBetween(LL_Element *One, LL_Element *Two)
{
	One->Next = Two;
	return One;
}

LL_Element *LL_AppendList(LL_Element *ListOne, LL_Element *ListTwo)
{
	ListOne->Next = ListTwo;
	return ListOne;
}

LL_Element *LL_InsertListIntoList(LL_Element *At, LL_Element *List)
{
	LL_Element *TempPointer = At->Next, *ListTempPointer = List;
	/* Find the end of the list */
	while(ListTempPointer->Next != NULL)
		ListTempPointer = ListTempPointer->Next;
	ListTempPointer->Next = TempPointer;
	At->Next = List;
	return At;
}
#ifdef __cplusplus
}
#endif
